package com.totoro.tymapping.manager;

import com.totoro.tymapping.TyMapping;
import org.bukkit.entity.Player;
import org.serverct.ersha.api.AttributeAPI;
import org.serverct.ersha.attribute.data.AttributeData;

import java.util.List;

/**
 * @author Totoro
 * @version 0.1.0
 * @date 2025/8/13 - 17:23
 * @description 属性管理器
 **/
public class AttributeManager {

    private final TyMapping plugin;

    public AttributeManager(TyMapping plugin) {
        this.plugin = plugin;
    }

    /**
     * @author totoro
     * @description 加载单个玩家的属性，自定义属性List
     * @date  10:44
     * @param p, attr
     * @return void
     **/
    public void loadAttribute(Player p, String attrSource, List<String> attr) {
        // 先获取该玩家所有属性数据
        AttributeData attributeData = AttributeAPI.getAttrData(p);
        // 删除一次属性源
        AttributeAPI.takeSourceAttribute(attributeData, attrSource);
        // 添加属性源
        AttributeAPI.addSourceAttribute(attributeData, attrSource, attr);
        updateAttribute(p);
    }

    public void updateAttribute(Player player) {
        AttributeAPI.updateAttribute(player);
    }

    public void deleteAttribute(Player p, String attrSource) {
        AttributeData attributeData = AttributeAPI.getAttrData(p);
        AttributeAPI.takeSourceAttribute(attributeData, attrSource);
        updateAttribute(p);
    }

}
